package cn.biao.epic.sys.modular.consts.controller;

import cn.biao.epic.base.pojo.page.AntdPageInfo;
import cn.biao.epic.core.base.controller.BaseController;
import cn.biao.epic.core.util.ToolUtil;
import cn.biao.epic.model.response.ResponseData;
import cn.biao.epic.sys.modular.consts.entity.EpicConfig;
import cn.biao.epic.sys.modular.consts.model.params.ConfigParam;
import cn.biao.epic.sys.modular.consts.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther Uncle_Z
 * @date 2019/12/17 14:07
 * @Email:2545375@qq.com
 * @Descrition
 */
@Controller
@RequestMapping("/sysConfig")
public class EpicConfigController extends BaseController {

    private String PREFIX="/modular/sysConfig";

    @Autowired
    private ConfigService configService;


    /**
     *
     * 增加设置
     *
     * @author uncle_z
     * @Date 2019/12/17 14:13
     * @Param [configParam]
     * @File EpicConfigController.java
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ConfigParam configParam) {
        configService.add(configParam);
        return ResponseData.success();
    }

    /**
     *
     * 删除设置
     *
     * @author uncle_z
     * @Date 2019/12/17 14:13
     * @Param [sysConfigParam]
     * @File EpicConfigController.java
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ConfigParam sysConfigParam) {
        this.configService.delete(sysConfigParam);
        return ResponseData.success();
    }

    /**
     *
     * 详情
     *
     * @author uncle_z
     * @Date 2019/12/17 14:13
     * @Param [sysConfigParam]
     * @File EpicConfigController.java
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ConfigParam sysConfigParam) {
        EpicConfig detail = this.configService.getById(sysConfigParam.getId());
        return ResponseData.success(detail);
    }

    /**
     *
     * 列表显示
     *
     * @author uncle_z
     * @Date 2019/12/17 14:13
     * @Param [condition]
     * @File EpicConfigController.java
     */
    @ResponseBody
    @RequestMapping("/list")
    public AntdPageInfo list(@RequestParam(value = "condition", required = false) String condition) {

        ConfigParam sysConfigParam = new ConfigParam();

        if (ToolUtil.isNotEmpty(condition)) {
            sysConfigParam.setCode(condition);
            sysConfigParam.setName(condition);
            sysConfigParam.setRemark(condition);
            sysConfigParam.setValue(condition);
        }
        return this.configService.findPageBySpec(sysConfigParam);
    }
}
